package com.rizhov.datastructures;

import java.util.ArrayList;

public class PriorityQueue <T> {
    
    public static interface IHasPriority {
	int getPriority();
    }
    
    /** collection store */
    private ArrayList<IHasPriority> store;
    
    public PriorityQueue() {
	store = new ArrayList<IHasPriority>();
    }
    
    public boolean isEmpty() {
	return store.isEmpty();
    }
    
    public void enqueue(IHasPriority newObject) {
	store.add(newObject);
    }
    
    public T dequeue() {
	if (isEmpty()) {
	    return null;
	}
	int lowestPriority = Integer.MAX_VALUE;
	int indexOfLowest = 0;
	for (int i = 0; i < store.size(); i++) {
	    if (store.get(i).getPriority() < lowestPriority) {
		lowestPriority = store.get(i).getPriority();
		indexOfLowest = i;
	    }
	}
	IHasPriority temp = store.get(indexOfLowest);
	store.remove(indexOfLowest);
	return (T) temp;
    }
}
